package com.calm.javapass;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //基本类型byte
        byte byte1 = (byte) 0xA;
        byte byte2 = (byte)0xB;
        swapByte(byte1,byte2);
        Log.e(TAG,"byte1="+byte1+" byte2="+byte2);
        //基本类型int
        int int1 = 1;
        int int2 = 9;
        swapInt(int1,int2);
        Log.e(TAG,"int1="+int1+" int2="+int2);
        //基本类型char
        char char1 = 'a';
        char char2 = 'b';
        swapChar(char1,char2);
        Log.e(TAG,"char1="+char1+" char2="+char2);
        //String
        String string1 = "string1";
        String string2 = "string2";
        swapString(string1,string2);
        Log.e(TAG,"string1="+string1+" string2="+string2);
        //集合类型 采用的是引用传递
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 5; i++){
            stringList.add("String"+i);
        }
        changStringList(stringList);
        for (String str : stringList){
            Log.e(TAG,str);
        }
        //类 采用的是引用传递
        Food food = new Food();
        food.food1 = "蔬菜";
        food.food2 = "嘎嘎";
        Log.e(TAG,food.toString());
        changeFood(food);
        Log.e(TAG,food.toString());

        //demo1
        String str=new String("hello");
        char []chs={'w','o','r','l','d'};
        change(str, chs);
        System.out.println(str+" "+new String(chs));

        //-------------------------------------------------
        //demo2

        StringBuffer sb=new StringBuffer("hello");
        change(sb);
        System.out.println(sb);
    }
    public void change(StringBuffer sb)
    {
        sb.append(" world");
    }
    public void change(String str,char[]chs)
    {
        str.replace('h', 'H');
        chs[0]='W';
    }
    private void swapByte(byte byte1,byte byte2){
        byte temp = byte1;
        byte1 = byte2;
        byte2 = temp;
        Log.e(TAG,"swapByte byte1="+byte1+" byte2="+byte2);
    }
    private void swapInt(int int1,int int2){
        int temp = int1;
        int1 = int2;
        int2 = temp;
        Log.e(TAG,"swapInt int1="+int1+" int2="+int2);
    }
    private void swapChar(char char1,char char2){
        char temp = char1;
        char1 = char2;
        char2 = temp;
        Log.e(TAG,"swapChar char1="+char1+" char2="+char2);
    }
    private void swapString(String string1,String string2){
        String temp = string1;
        string1 = string2;
        string2 = temp;
        Log.e(TAG,"swapString string1="+string1+" string2="+string2);
    }
    private void changStringList(List<String> stringList){
        stringList.remove(0);
        for (String str : stringList){
            Log.e(TAG,"changStringList "+str);
        }
    }
    private class Food{
        public String food1;
        public String food2;

        @Override
        public String toString() {
            return food1+" "+food2;
        }
    }
    private void changeFood(Food food){
        food.food1 = "水果";
        food.food2 = "新鲜蔬菜";
        Log.e(TAG,"changeFood "+food.toString());
    }
}
